package calao.contact.client;

import calao.client.Desktop;
import calao.client.ServiceCallback;
import calao.client.ui.Form;
import calao.client.ui.Link;

public class ContactLink
extends Link
{
	
	class ViewCallback
	extends ServiceCallback
	{
		protected void onReturn(Object result) {
			Contact info = (Contact)result;
			if (info!=null)	show(new ContactPanel(info, Form.VIEW, ContactMod.canModify()));
		}		
	}
	
	int id;
	
	public ContactLink() 
	{
		setWordWrap(false);
	}
	
	public void setText(String text)
	{
		super.setText(text);
		setTitle(text);
	}

	public ContactLink(int id)
	{
		this();
		setContact(id);
	}

	public ContactLink(Contact info)
	{
		this();
		setContact(info);
	}

	protected void onClick() 
	{
		ContactMod.instance.getService().getContactDetails(id, new ViewCallback());
	}
	
	public void setContact(int id)
	{
		this.id = id;
		setText(ContactMod.getMod().getContactName(id));
	}
	
	public void setContact(Contact contact)
	{
		this.id = contact.id;
		setText(contact.getLabel());		
	}
	
	protected void show(ContactPanel panel)
	{
		Desktop.getDesktop().stackView(panel);
	}

}
